import { defineStore } from "pinia";
import { store } from "../index";
import { getStorage, setStorage } from "../../utils/tools";

export const useProductStore = defineStore("product", {
  state: () => ({
    productInfo: getStorage("commer-productInfo") || {},
    submitInfo: getStorage("commer-submitInfo") || {},
  }),
  getters: {},
  actions: {
    setProductInfo(data: any) {
      this.productInfo = data;
      setStorage("commer-productInfo", data);
    },
    setSubmitInfo(data: any) {
      this.submitInfo = data;
      setStorage("commer-submitInfo", data);
    },
  },
});

export function getProductStore() {
  return useProductStore(store);
}
